﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using rock.DAL;
using rock.UI.common;

namespace rock.UI.custom
{
    public partial class UserControlLeftTree : UserControl
    {
        public UserControlLeftTree()
        {
            InitializeComponent();
        }

        DalHOUSE_XIAOQU dalHOUSE_XIAOQU = new DalHOUSE_XIAOQU();
        DalHOUSE_DONG dalHOUSE_DONG = new DalHOUSE_DONG();

        private void UserControlLeftTree_Load(object sender, EventArgs e)
        {
            DataSet dsxiaoqu = dalHOUSE_XIAOQU.GetList("");
            TreeNode all = new TreeNode();
            all.Tag = new TreeInfo() { Id = 0, Name = "所有", NodeType = 0 };
            all.Text = "所有";
            this.treeView1.Nodes.Add(all);

            for (int i = 0; i < dsxiaoqu.Tables[0].Rows.Count; i++)
            {
                String xiaoquName = (String)dsxiaoqu.Tables[0].Rows[i]["NAME"];

                int seqid = (int)dsxiaoqu.Tables[0].Rows[i]["SEQID"];
                DataSet dsdong = dalHOUSE_DONG.GetList(" HOUSE_DONG.HOUSE_XIAOQU_SEQID =" + seqid + " ORDER BY HOUSE_DONG.NAME ASC");
                TreeNode xiaoquNode = new TreeNode();
                xiaoquNode.Text = xiaoquName;
                xiaoquNode.Tag = new TreeInfo() { Id = seqid, Name = xiaoquName, NodeType = 1 };
                all.Nodes.Add(xiaoquNode);


                for (int j = 0; j < dsdong.Tables[0].Rows.Count; j++)
                {
                    String dongName = (String)dsdong.Tables[0].Rows[j]["DONG_NAME"];
                    int dongId = (int)dsdong.Tables[0].Rows[j]["SEQID"];
    
                    TreeNode dongNote = new TreeNode();
                    dongNote.Text = dongName;
                    dongNote.Tag = new TreeInfo() { Id = dongId, Name = dongName, NodeType = 2 };
                    xiaoquNode.Nodes.Add(dongNote);

                }


            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {

            TreeNode selectNode = this.treeView1.SelectedNode;
            TreeInfo treeinfo = (TreeInfo)selectNode.Tag;
            this.label2.Text = treeinfo.Name +"";
            selectedTreeinfo(treeinfo);
        }


        //代理
        public delegate void SelectedTreeinfo(TreeInfo selectedTreeinfo);
        public SelectedTreeinfo selectedTreeinfo;

        private void label2_Click(object sender, EventArgs e)
        {

        }




        
    }
}
